package com.example.xm.ui.discover;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.example.xm.R;
import com.example.xm.adapter.DiscoverAdapter.DiscoverReMenAdapter;
import com.example.xm.adapter.HomeAdapter.DiscoverVpTabAdapter;
import com.example.xm.base.BaseFragment;
import com.example.xm.bean.DiscoverBean.DiscoverPagerBean;
import com.example.xm.bean.DiscoverBean.DiscoverPaoZhiBean;
import com.example.xm.bean.DiscoverBean.DiscoverReMenBean;
import com.example.xm.interfaces.discover.IDiscover;
import com.example.xm.presenter.discover.DiscoverPresenter;
import com.example.xm.ui.discover.fragment.ReDianFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class DiscoverFragment extends BaseFragment<IDiscover.Presenter> implements IDiscover.View {

    @BindView(R.id.toolbar_iv_back)
    ImageView toolbarIvBack;
    @BindView(R.id.toolbar_tv_title)
    TextView toolbarTvTitle;
    @BindView(R.id.toolbar_iv_dian)
    ImageView toolbarIvDian;
    @BindView(R.id.iv_paozi)
    ImageView ivPaozi;
    @BindView(R.id.ll1_discover)
    LinearLayout ll1Discover;
    @BindView(R.id.iv_shetuan)
    ImageView ivShetuan;
    @BindView(R.id.ll2_discover)
    LinearLayout ll2Discover;
    @BindView(R.id.iv_paihangbang)
    ImageView ivPaihangbang;
    @BindView(R.id.ll3_discover)
    LinearLayout ll3Discover;
    @BindView(R.id.tv_remen)
    TextView tvRemen;
    @BindView(R.id.rlv_remen)
    RecyclerView rlvRemen;
    @BindView(R.id.v_discover)
    View vDiscover;
    @BindView(R.id.ll_discover)
    LinearLayout llDiscover;
    @BindView(R.id.tab_discover)
    TabLayout tabDiscover;
    @BindView(R.id.vp_discover)
    ViewPager vpDiscover;
    private ArrayList<DiscoverReMenBean.DataBean> list;
    private DiscoverReMenAdapter discoverReMenAdapter;
    private ArrayList<Fragment> fragments;
    private String[] title = {"热点", "妆造", "图赏", "百科"};

    @Override
    protected IDiscover.Presenter initPresenter() {
        return new DiscoverPresenter();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_discover;
    }

    @Override
    protected void initView() {
        setToolbar();
        setRlv();
        setTab();
    }

    private void setTab() {
        fragments = new ArrayList<>();
        fragments.add(new ReDianFragment(1));
        fragments.add(new ReDianFragment(2));
        fragments.add(new ReDianFragment(3));
        fragments.add(new ReDianFragment(4));
        tabDiscover.setupWithViewPager(vpDiscover);
        DiscoverVpTabAdapter vpTabAdapter = new DiscoverVpTabAdapter(getFragmentManager(), fragments, title);
        vpDiscover.setAdapter(vpTabAdapter);
    }

    private void setRlv() {
        list = new ArrayList<>();
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rlvRemen.setLayoutManager(manager);
        discoverReMenAdapter = new DiscoverReMenAdapter(getActivity(), list);
        rlvRemen.setAdapter(discoverReMenAdapter);
    }

    private void setToolbar() {
        toolbarIvBack.setVisibility(View.INVISIBLE);
        toolbarTvTitle.setText("发现");
        toolbarIvDian.setVisibility(View.GONE);
    }

    @Override
    protected void initData() {
        mPresenter.getReMen();
        mPresenter.getPaoZhi();

    }

    @Override
    protected void initListener() {

    }

    @Override
    public void showTips(String tips) {

    }

    @Override
    public void showLoading(int visble) {

    }

    @Override
    public void getReMenResult(DiscoverReMenBean result) {
        if (result.getStatus().getStatusCode() == 100) {
            List<DiscoverReMenBean.DataBean> data = result.getData();
            list.addAll(data);
            discoverReMenAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void getPaoZhiResult(DiscoverPaoZhiBean result) {
        if (result.getStatus().getStatusCode() == 100) {
            
        }
    }

    @Override
    public void getPagerResult(DiscoverPagerBean result) {

    }
}